const util = require('../../utils/util') 
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    intime: {
      type: String,
      value: '0',
      observer: function(newVal, oldVal) {
        // 属性值变化时执行
        if(newVal==null) return;
        this.setData({
          nowTime:newVal
        })
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    name: 'date-picker',
    nowTime:'',
    time_list:[],
    multiArray:[],
    multiIndex:[0,0,0,0,0] //当前默认选择下标
  },
  attached: function () {
    this._initData()
    this._setNonTime()
    // console.log(this.data.min)
   
  },
  /**
   * 组件的方法列表
   */
  methods: {
    _initData: function () {
      
      var date = new Date();
      var Y = date.getFullYear();
      var M = date.getMonth()+1;
      var D = date.getDate()
      var H = date.getHours();
      var MI = date.getMinutes();

      var _years = util.range_list(Y,Y+2,'年')
      var _months = util.range_list(1,12,'月')
      var _days = util.range_list(1,31,'日')
      var _hours = util.range_list(0,23,'时')
      var _mins = util.range_list(0,59,'分')
      console.log(M)
      this.setData({
        multiArray:[_years,_months,_days,_hours,_mins],
        time_list:[Y+'年',M+'月',D+'日',_hours[0],_mins[0]],
        multiIndex:[
         _years.indexOf(Y+'年'),
         _months.indexOf(M+'月'),
         _days.indexOf(D+'日'),
        ]
      })


    },
    
    _setNonTime(){
      var list = this.data.time_list
      var time_str=''
      for (let index = 0; index < list.length; index++) {
        var t = list[index] + '';
        var dict_t = ['-','-',' ',':','']
        time_str += t.slice(0,-1) + dict_t[index]
      }
      this.setData({
        nowTime:time_str,
      })
    },



    /**
     * 滚动时更新时间
     */
    _bindChange: function (e) {
      const val = e.detail.value
      this.setData({
        year: this.data.years[val[0]],
        month: this.data.months[val[1]],
        day: this.data.days[val[2]],
        hour: this.data.hours[val[3]],
        min: this.data.mins[val[4]]
      })
    },
    _bindMultiPickerChange:function (e) {
      
      // console.log('picker发送选择改变，携带值为', x,y)
    },
    /**
     * 滚动更新值
     * @param {*} e 
     */
    _bindMultiPickerColumnChange:function (e) {
      var x = e.detail.column
      var y = e.detail.value
      var list = this.data.time_list
      list[x] = this.data.multiArray[x][y]
      this.setData({
        time_list:list
      })
      this._setNonTime()
      console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    }
  }

})